package com.xjh.mange.service.Impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xjh.mange.mapper.GoodsMapper;
import com.xjh.mange.model.Goods;
import com.xjh.mange.service.GoodsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @author 徐佳辉
 * @date 2020/8/6 15:12
 */
@Slf4j
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements GoodsService {


    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public IPage<Goods> page(int page, int limit) {
        IPage<Goods> page1 = new Page<>(page, limit);
        QueryWrapper<Goods> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("create_time");
        goodsMapper.selectPage(page1, wrapper);
        return page1;
    }

    @Override
    public IPage<Goods> pageByName(int page, int limit, String name) {
        IPage<Goods> page1 = new Page<>(page, limit);
        QueryWrapper<Goods> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("create_time");
        wrapper.like("good_name", name);
        goodsMapper.selectPage(page1, wrapper);
        return page1;
    }
}
